<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>修改密码</title>
	<script type="text/javascript" src="scripts/jquery-1.7.2.min.js"></script>
	<script type="text/javascript">
	 $(function(){
		 var uidFlag=false;
		 var upasswordFlag=false;
		 var newpasswordFlag=false;
		 var repasswordFlag=false;
		 //效验用户名（uid）
		$("#uid").blur(function(){
			//alert("失去输入用户账号焦点了");
			var uid = $("#uid").val();
			//alert("测试uid的值"+uid);
			$.ajax({
				//alert("失去焦点测试");//这里面不能用
				url:"checkUidServlet",
				type:"post",
				data:"uid="+uid,
				success:function(data){
					if(data==1){
						$("#uid_span").html("用户名不存在，请重新输入");
					}
					else{
						uidFlag=true;
						$("#uid_span").html("");
					}
				}
			});
		});
		
		//效验密码（password）
		$("#upw").blur(function(){
			//alert("失去输入用户密码账号焦点了");
			var uid = $("#uid").val();
			var upw = $("#upw").val();
			
			//alert(uid+"\n"+upw);
			
			//alert("测试uid的值"+uid);
			$.ajax({
				//alert("失去焦点测试");//这里面不能用
				//url:"query",//和query公用一个servlet好像不行，先改一下其他方法了，这个方式到时候再看
				url:"checkUpwServlet",
				type:"post",
				data:{"uid":uid,"upw":upw},
				success:function(data){
					if(data==1){
						$("#misspassword").html("用户密码错误，请重新输入");
						upasswordFlag=false;
					}
					else{
						upasswordFlag=true;
						$("#misspassword").html("");
					}
				}
			});
		});
		
		//var upw=$("#upw").val();
		//alert("upw: "+upw);
		//var password=$("#password").val();
		var repassword=$("#repassword").val();
		//判断新密码和原密码是否相同
		$("#password").blur(function(){
			var upw=$("#upw").val();
			var password=$("#password").val();
			//alert("newpassword: "+password);
			if(upw==password&&password!=null&&password!=""){
				$("#newpassword_span").html("新密码和原密码相同，请更换");
				newpasswordFlag=false;
			}
			else{
				newpasswordFlag=true;
			}
		});
		
		//判断新密码和确认密码是否相同
		$("#repassword").blur(function(){
			var password=$("#password").val();
			var repassword=$("#repassword").val();
			//alert("repassword: "+repassword);
			if(repassword!=password&&repassword!=null&&repassword!=""){
				$("#repassword_span").html("新密码和确认密码不相同，请重新输入");
				repasswordFlag=false;
			}
			else{
				repasswordFlag=true;
			}
		});
		
		//去掉用户id错误提示信息
		$("#upw").focus(function(){
			$("#misspassword").html("");
		});
		
		//去掉用户密码错误提示信息
		$("#upw").focus(function(){
			$("#missMsg").html("");
		});
		
		//去掉用户新密码错误提示信息
		$("#password").focus(function(){
			$("#newpassword_span").html("");
		});
		
		//去掉用户确认密码错误提示信息
		$("#repassword").focus(function(){
			$("#repassword_span").html("");
		});
		
		//让用户uid、newpassword,renewpassword对应的输入正确才能提交表单
		$("#submit").click(function(){
			//alert("uidFlag: "+uidFlag+"\nupasswordFlag: "+upasswordFlag+"\nnewpasswordFlag: "+newpasswordFlag+"\nrepasswordFlag: "+repasswordFlag);
			if(uidFlag==true&&upassword==true&&newpasswordFlag==true&&repasswordFlag==true){
				return true;
			}else{
				return false;
			}
			
		});
		
		//点击输入用户账号的时候，之前的成功信息或者错误信息消失
		$("#uid").click(function(){
			$("#alert_span").html("");
		});
	}); 
	</script>
</head>
<body>
	<h3>公积金账户密码修改</h3>
		<form action="repassword" method="post">
			<table>
				<tr>
					<td>身份证号：</td>
					<td><input type="text" name="uid" id="uid" value="${uid }"></td>
					<td><font color="red"><span id="uid_span"></span></font>
				</tr>
				<tr>
					<td>旧密码：</td>
					<td><input type="password" name="upw" id="upw"></td>
					<td><span id="misspassword"></span></td>
				</tr>
				<tr>
					<td>新密码：</td>
					<td><input type="password" name="password" id="password"></td>
					<td><span id="newpassword_span"></span></td>
				</tr>
				<tr>
					<td>确认密码：</td>
					<td><input type="password" name="repassword" id="repassword"></td>
					<td><span id="repassword_span"></span></td>
				</tr>
				<tr>
					<td>
						<input type="submit" id="submit" value="提交"/>
					</td>
				</tr>
			</table>
		</form>
		<font><span id="alert_span">${alertMsg }</span></font>
		<a href="/finance3/query.jsp">登录</a>
</body>
</html>